<template>
    <div class="container-box-container">
        <div class="control-area border-radius8">
            <div class="flex-box flex-center flex-align-items-center">
                <div class="margin320 width-25 text-center rightBorder">
                    <p class="fontSize16 color333">出租中</p>
                    <p class="fontSize30 colorMain line-height55 margin0">{{data.statisticsObj&&data.statisticsObj.leaseInTotal ? data.statisticsObj.leaseInTotal : 0}}</p>
                </div>
                <div class="margin320 width-25 text-center rightBorder">
                    <p class="fontSize16 color333">已出租</p>
                    <p class="fontSize30 colorMain line-height55 margin0">{{data.statisticsObj&&data.statisticsObj.sellTotal ? data.statisticsObj.sellTotal : 0}}</p>
                </div>
                <div class="margin320 width-25 text-center">
                    <p class="fontSize16 color333">已取消</p>
                    <p class="fontSize30 colorMain line-height55 margin0">{{data.statisticsObj&&data.statisticsObj.cancelTotal ? data.statisticsObj.cancelTotal : 0}}</p>
                </div>
            </div>
        </div>
        <Page class="main_content">
            <PageCard title="房屋租赁列表" class="margin0">
                <template #actions>
                <el-button class="ed-button ed_black-bottom ed-button36" @click="add()" v-has="'property:houseRent:add'"><svg-icon icon-class="add-svg"/>新增</el-button>
                </template>
                <div class="content">
                    <div class="search_box">
                        <HousePicker class="mr-2" ref="housePicker" multiple v-model="queryForm.rooms" @input="houseInput"/>
                        <EdSelect v-model="queryForm.rentWay" :selectParams="data.selectRentMethod"></EdSelect> 
                        <EdSelect v-model="queryForm.leaseStatus" :selectParams="data.selectStatus"></EdSelect>                        
                        <EdDateTimePickerRange v-model="queryForm.pickerTime"  @emit-echo-time-range="emitEchoTimeDate($event, 'pickerTime')" :pickerParams="data.pickerRangeParams"></EdDateTimePickerRange>
                        <el-button class="ed-button ed_black-bottom" @click="search()"><svg-icon class="svg-middle" icon-class="search-svg"/>查 询</el-button>
                        <el-button class="ed-button ed_white_bottom" @click="reset()"><svg-icon icon-class="reset-svg"/>重 置</el-button>
                    </div>
                    <ApiTable :api="api.houseRentList" ref="table" :params="queryForm">
                        <el-table-column type="index" width="80" label="序号"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="villageName" label="所属项目" :formatter="formatter"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="addressPart" label="房间号" :formatter="formatter"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="rentWay" label="出租方式">
                            <template slot-scope="scope">
                                <span v-if="scope.row.rentWay==1">整租</span>
                                <span v-if="scope.row.rentWay==2">合租</span>
                                <!-- <span>{{returnName(scope.row['rentMethod'], selectRentMethod.options) || scope.row['rentMethod'] || '-'}}</span> -->
                            </template>
                        </el-table-column>
                        <el-table-column :show-overflow-tooltip="true"  label="户型" :formatter="formatter">
                            <template slot-scope="scope">
                                {{scope.row.room}}室{{scope.row.hall}}厅{{scope.row.kitchen}}厨{{scope.row.toilets}}卫
                            </template>
                        </el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="rent" label="租金/月" :formatter="formatter"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建时间" :formatter="formatter"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="leaseStatus" label="状态">
                            <template slot-scope="scope">
                                <div><span :class="['spanLabel spanLabelWidth marginRight8', 'spanLabelColor'+scope.row.leaseStatus]"></span>{{returnName(scope.row['leaseStatus'], data.selectStatus.options) || scope.row['leaseStatus'] || '-'}}</div>
                                <!-- <span>{{returnName(scope.row['status'], selectStatus.options) || scope.row['status'] || '-'}}</span> -->
                            </template>
                        </el-table-column>
           s             <el-table-column :show-overflow-tooltip="true" prop="" label="操作" width="150">
                            <template slot-scope="scope">
                                <el-button class="ed-table-bottom ed_black_border" v-has="'property:houseRent:detail'" @click="seeRow(scope.row)">查看</el-button>
                                <el-button class="ed-table-bottom ed_delete_border" v-has="'property:houseRent:del'" @click="del(scope.row)" :disabled="scope.row.leaseStatus==1 || scope.row.leaseStatus==2">删除</el-button>
                            </template>
                        </el-table-column>
                    </ApiTable>
                </div>
            </PageCard>
            <EdConfirmDelete ref="confirmDeleteRef" @confirmDeleteTrue="confirmDeleteTrue"></EdConfirmDelete>
        </Page>
    </div>
</template>

<script setup>
    import EdSelect from 'src/components/EdSelect.vue'
    import HousePicker from 'src/components/HousePicker/index.vue'
    import EdDateTimePickerRange from 'src/components/EdDateTimePickerRange.vue'  
    import * as api from './api'  
    import Page from '../../components/Page.vue'
    import PageCard from 'src/views/components/PageCard.vue'
    import ApiTable from 'src/components/ApiTable.vue'
    import {reactive, onActivated,nextTick ,ref } from 'vue'
    import EdConfirmDelete from "src/components/EdConfirmDelete.vue";
    import { returnName } from "src/utils/common.js";
    import message from 'src/utils/once-message'
    import router from 'src/router'

    const queryForm = reactive({
            rooms: undefined,
            rentWay: '',
            leaseStatus: '',
            pickerTime: '',
            startTime:"",
            endTime:"",
    })
    const table = ref()
    const confirmDeleteRef = ref()
    const data = reactive({
        pickerRangeParams:{
            valueFormat:"yyyy-MM-dd HH:mm"
        },
        statisticsObj: {
            cancelTotal: '',
            leaseInTotal: '',
            sellTotal: '',
        },
        selectStatus:{  // 状态
            placeholder:"请选择状态",
            options: [
                { value: '1', label: '出租中' },
                { value: '2', label: '已出租' },
                { value: '0', label: '已取消' },
            ]
        },
        selectRentMethod:{  // 出租方式
            placeholder:"请选择出租方式",
            options: [
                { value: '1', label: '整租' },
                { value: '2', label: '合租' },
            ]
        },
        confirmRow:''
    })

    onActivated(()=>{
        getStaticsData()
        nextTick(()=>{
            table.value.load(1)
        })
    })

    function getStaticsData(){
        api.getStaticsData({}).then(response => {
            if(response.success) {
                data.statisticsObj.cancelTotal = response.data.cancelTotal;
                data.statisticsObj.leaseInTotal = response.data.leaseInTotal;
                data.statisticsObj.sellTotal = response.data.sellTotal;
            }
        })
    }
    function search(){
        table.value.load(1)
    }
    function reset(){
        Object.assign(queryForm,{
            rooms: undefined,
            rentWay: '',
            leaseStatus: '',
            pickerTime: '',
            startTime:"",
            endTime:"",
        })
        nextTick(()=>{
           table.value.load(1,10)
        })
    }
    function add(){
        router.push({
            path: '/property/houseRent-add',
            query: {},
        })
    }
    function seeRow(row){
       router.push({
            path: '/property/houseRent-detail',
            query: {leaseStatus:row.leaseStatus,id:row.id},
        })
    }
    function emitEchoTimeDate(data){
        queryForm['startTime'] = data.startTime;
        queryForm['endTime'] = data.endTime;
    }
    function formatter(row, column, cellValue, index){
        return cellValue || '-'
    }
    function houseInput(data){
        console.log('=====',data);
    }
    function del(row){
        data.confirmRow = row;
        confirmDeleteRef.value.open("删除确认","确认删除此项数据？","warning")
    }
    // 删除回调
    function confirmDeleteTrue(){
        api.houseRentDelete({id: data.confirmRow.id}).then(response => {
            if(response.success == true) {
                message.success({ 
                    message: '删除成功！',
                    duration: 2000,
                    center:true
                });
                table.value.load()
            }
        })
    }
</script>

<style scoped lang="scss">
    .spanLabel{
        width: 8px;height: 8px;border-radius: 50%;display: inline-block;vertical-align: 1px
    }
    .spanLabelWidth{
        width: 6px;height: 6px;
    }
    .titleTop{
        border: 1px solid rgba(0, 0, 0, 0.65);width: 14px;height: 14px;line-height: 14px;
        border-radius: 50%;font-size: 12px;text-align: center;display: inline-block;vertical-align: 1px;margin-left: 4px;
    }

    .titleTopBorderColor1{
        border-color: rgba(0, 0, 0, 0.65);
    }
    .titleTopBorderColor2{
        border-color: #FAAD14;
    }
    .titleTopBorderColor3{
        border-color: #52C41A;
    }
    .titleTopBorderColor4{
        border-color: #1890FF;
    }
    .titleTopBorderColor5{
        border-color: #B7B7B7;
    }
    .spanLabelColor0{
        background-color: #B9B9B9 !important;
    }
    .spanLabelColor1{
        background-color: #EED096 !important;
    }
    .spanLabelColor2{
        background-color: #414448 !important;
    }
    .colorMain{
        color: #DDB15C !important;
    }
    :deep .main_content {
        >.header{
            display:none !important;
        }
        .search_box{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            margin-bottom: 20px;
            >div{
                margin-right: 10px;
            }
        }
        .content .el-input {
            width: unset;
        }
    }
</style>